#!/bin/bash

#  So we we moved the package.json file out of the way in pre_build,
#  so that the OpenShift git post-receive hook doesn't try and use the
#  old npm version to install the dependencies. Move it back in.
[ -d "$OPENSHIFT_DATA_DIR/.nodejs.tmp" ]  ||  mkdir -p "$OPENSHIFT_DATA_DIR/.nodejs.tmp"
if [ -f "$OPENSHIFT_DATA_DIR/.nodejs.tmp/package.json" ]; then
   #  Only overlay it if there is no current package.json file.
   [ -f "${OPENSHIFT_REPO_DIR}/package.json" ]  ||    \
      mv "$OPENSHIFT_DATA_DIR/.nodejs.tmp/package.json" "${OPENSHIFT_REPO_DIR}/package.json"
fi


#  Do npm install with the new npm binary.
if [ -f "${OPENSHIFT_REPO_DIR}"/package.json ]; then
   echo "  - Installing dependencies w/ new version of npm ... "
   echo
   (cd "${OPENSHIFT_REPO_DIR}"; export TMPDIR="/tmp"; npm install -d)
fi
